<?php
/**
 * @file tags.php
 * @author CaoQiCheng
 * @date 2017年2月8日 下午17:05:11
 * @brief 
 */
namespace haibao\jiepai\business;

use haibao\jiepai\data\Goods as GoodsData;

class Goods extends \haibao\jiepai\business\Base{	
	
	/**
	 * 状态码
	 */
	public static $GoodsStatus = array(
			1 => '未使用',
			2 => '未发布',
			3 => '已关闭'
	);
	
	/**
	 * 金钱对应关系
	 */
	public static $currency = array(
			'USD'=>'USD 美元',
			'RMB'=>'RMB 人民币',
			'EUR'=>'EUR 欧元',
			'GBP'=>'GBP 英镑',
			'JPY'=>'JPY 日元',
			'KRW'=>'KRW 韩元',
			'HKD'=>'HKD 港币',
			'TWD'=>'TWD 新台币',
			'MOP'=>'MOP 澳门元',
			'AUD'=>'AUD 澳大利亚元',
			'CHF'=>'CHF 瑞士法郎',
			'CAD'=>'CAD 加拿大元',
			'RUB'=>'RUB 俄罗斯卢布',
			'SGD'=>'SGD 新加坡元',
			'NT$'=>'NT$ 新台币',
			'AED'=>'AED 阿联酋迪拉姆',
	);

	public static function getGoodsByFilter($query){
		$data = new GoodsData();
		return $data->getAll($query);
	}
	
	public static function getGoodsInfo($query){
		$data = new GoodsData();
		return $data->getOne($query);
	}
	/**
	 * 
	 * @param 商品实体 $goodsModel
	 * @param 所有需要插入的tag $tagArr
	 */
	public static function saveGoods($goodsModel,$tagArr=array(),$goodsPicture=array(),$stylePicture=array()){
		$data = new GoodsData();
		
		if (in_array(\haibao\cms\business\base::getCurrentUser()->Id, array_keys(\haibao\jiepai\business\Base::$userMap))) {
			$goodsModel->EditorID = \haibao\jiepai\business\Base::$userMap[\haibao\cms\business\base::getCurrentUser()->Id]['id'];
		} else {
			$goodsModel->EditorID = 5;
		}
		
		return $data->saveGoods($goodsModel,$tagArr,$goodsPicture,$stylePicture);
	}
	
	public static function getGoodsInfoById($goodsId){
		$data = new GoodsData();
		return $data->getOneById($goodsId);
	}
	
	public static function changeFlag($goodsId,$flag=0){
		$data = new GoodsData();
		return $data->changeFlag($goodsId,$flag);
	}
}